package com.david.reader.activity

import android.graphics.Color
import android.os.Bundle
import android.view.*
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity

/**
 * 默认书籍都存储在documents文件夹中，不在此文件夹提示书籍不存在
 *
 * 默认获取所以文件权限，使用绝对路径读取书籍
 */
abstract class BaseActivity:AppCompatActivity() {
    var id:String? = ""
    var name:String = ""
    private var position:Int = 0

    /**
     * 用于存储页数及总页数，用于列表计算进度及复原阅读进度
     */
    var page = 0//用于计算进度及下次打开时跳转对应页面
    var pageCount = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        initSystemBars()
        super.onCreate(savedInstanceState)

        initView()
        initData()
    }

    open fun initData() {
        id = intent.getStringExtra("id")
        name = intent.getStringExtra("name")?:""
        position = intent.getIntExtra("position", 0)
    }

    open fun initView() {
        val frameLayout = FrameLayout(this)
        frameLayout.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        frameLayout.addView(getReadView())

//        frameLayout.addView()

        setContentView(frameLayout)
    }

    abstract fun getReadView(): View

    private fun initSystemBars() {
        window.statusBarColor = Color.TRANSPARENT
        window.navigationBarColor = Color.TRANSPARENT
        requestWindowFeature(Window.FEATURE_NO_TITLE)
    }
}